package net.system.sys.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.core.base.dao.CommonDAO;
import net.core.common.StrUtils;
import net.system.base.bean.SSysnotice;
import net.system.base.bean.SSysnoticeExample;
import net.system.sys.dao.SSysnoticeDAO;

@Service
public class NoticeServiceImpl implements INoticeService {
	@Autowired
	private SSysnoticeDAO dao;
	@Autowired
	private ICommService commService;
	@Autowired
	private CommonDAO commonDAO;

	@Override
	public List<SSysnotice> select(HashMap map) {
		SSysnoticeExample example = new SSysnoticeExample();
		SSysnoticeExample.Criteria c = example.createCriteria();
		String type = StrUtils.getNotNullStrValue(map.get("funid"));
		c.andSnTypeEqualTo(type);
		List<SSysnotice> list = dao.selectByExample(example);
		return list;
	}

	@Override
	public SSysnotice getBean(String recId) {
		// TODO Auto-generated method stub
		return dao.selectByPrimaryKey(recId);
	}

	@Override
	public void insert(HashMap map) {
		SSysnotice record = new SSysnotice();
		record.setRecId(commService.getSeq("notice"));
		record.setSnTitle(StrUtils.getNotNullStrValue(map.get("snTitle")));
		record.setSnContent(StrUtils.getNotNullStrValue(map.get("snContent")));
		record.setSnType(StrUtils.getNotNullStrValue(map.get("type")));
		record.setSnIspub("1");
		record.setRecTime(new Date());
		record.setRecStatus("1");

		dao.insert(record);

	}

	@Override
	public void update(HashMap map) {
		SSysnotice record = new SSysnotice();
		record.setRecId(StrUtils.getNotNullStrValue(map.get("recId")));
		record.setSnTitle(StrUtils.getNotNullStrValue(map.get("snTitle")));
		record.setSnContent(StrUtils.getNotNullStrValue(map.get("snContent")));
		record.setRecUpdatetime(new Date());
		dao.updateByPrimaryKeySelective(record);

	}

	@Override
	public List<HashMap> selectTop(int i,String type) {
		String sql = "SELECT t.sn_title,t.rec_id FROM s_sysnotice t "
				+ " WHERE t.sn_ispub='1' and t.sn_type='"+type+"' and t.REC_STATUS='1' "
				+ " ORDER BY t.REC_TIME DESC " + " LIMIT 0," + i;
		List<HashMap> list = commonDAO.getDataList(sql);
		return list;
	}


}
